﻿using XYX.Http.Mvc;
using System.Collections.Generic;
using System;
using System.IO;
using System.Linq;

/// <summary>
/// 备注:要求 自定义对象或者集合放参数最后面
/// </summary>
namespace HttpApiMethod
{
    /// <summary>
    /// 测试
    /// </summary>
    public class TestController : Controller
    {
   
        /// <summary>
        /// 视图
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            // return View("Index.html");
            return View();

        }
        /// <summary>
        /// 获取
        /// </summary>
        /// <returns></returns>
        public ActionResult GetListJson()
        {
            List<User> list = new List<User>();
         
            IAdapter adapter = new TestAdapter();
            var result = adapter.GetList();

            return Json(list, JsonRequestBehavior.AllowGet);
        }

        #region 重载
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
        public ActionResult GetListText(List<User> users)
        {
            string msg = string.Empty;
            string text = string.Empty;
            if (users == null)
            {
                text = JsonUitl.ToJson(new  { Code = 500, Msg = msg });
            }
            else
            {
                users = new List<User>()
                   {
                    new User(){ Phone="13800138000",Name="xialei" },
                    new User(){ Phone="13800138000",Name="zhangsanfeng" },
                   };
                text = JsonUitl.ToJson(users);
            }
            // lbl:
            return Content(text, "text/plain", System.Text.Encoding.Default);
        }

        /// <summary>
        /// 获取
        /// <![CDATA[参数对象放最后面]]>
        /// </summary>
        /// <param name="parma1"></param>
        /// <param name="parma2"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public ActionResult GetListText1(int parma1, int parma2, List<User> users)
        {
            if (users == null)
            {
                users = new List<User>();
            }
            users = new List<User>()
                   {
                    new User(){ Phone="13800138000",Name="xialei" },
                    new User(){ Phone="13800138000",Name="zhangsanfeng" },
                   };

            return Json(users, JsonRequestBehavior.AllowGet);

        }
        /// <summary>
        /// 获取,枚举
        /// </summary>
        /// <param name="parma1"></param>
        /// <param name="parma2"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public ActionResult GetEnums(int parma1, int parma2, List<User> users)
        {
            string text = "fdsafdsafdsafdsafdsa";
            return Content(text, "text/plain", System.Text.Encoding.Default);



        }

        #endregion


        public ActionResult GetImage()
        {

            string imageFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "王宝强.jpg");
            if (!File.Exists(imageFilePath))
            {
                throw  new  FileNotFoundException(imageFilePath);
            }
            return DownFile(imageFilePath);

        }

        public ActionResult GetImage1()
        {
            string imageFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "王宝强.jpg");
            if (!File.Exists(imageFilePath))
            {
                throw new FileNotFoundException(imageFilePath);
            }
            return DownFile(imageFilePath);

        }



        

        public List<string> GetString()
        {
            throw new NotImplementedException();
        }

       
    }
}
